package com.iwhalecloud.uncc.utils;

import com.iwhalecloud.uncc.service.ArchiverService;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zq
 * @date 2021/10/31 10:49
 * @description
 */
public class DivideUtil {
    public static <T> void  divideSend(ArchiverService<T> archiverService,List<T> list) {
        int size = list.size();
        int t = SendUtil.getSendTimes(size);
        if(t == size){
            list.forEach(i->archiverService.packMsg(list));
        }else{
            List<T> oneSendList = new ArrayList<>();
            int v = 0;
            for (int i = 0; i < t; i++ ){
                int n = SendUtil.getOneSendNum(size-v);
                for (int j = 0; j < n; j++ ){
                    oneSendList.add(list.get(v++));
                }
                archiverService.packMsg(oneSendList);
                oneSendList.clear();
            }
        }
    }
}
